package com.wuhan.template.module.home.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;

import com.google.gson.Gson;
import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.wuhan.template.R;
import com.wuhan.template.base.BaseFragment;
import com.wuhan.template.constant.Urls;
import com.wuhan.template.module.home.adapter.DianShiBaseAdapter;
import com.wuhan.template.module.home.entity.DianShiEntity;
import com.wuhan.template.utils.EventMessage;
import com.wuhan.template.utils.OkHttpUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/5/12 0012.
 */
public class GuangBoFragment extends BaseFragment{

    @BindView(R.id.guangbo_pullListView)
    protected PullToRefreshListView listView;

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_guangbo;
    }

    public GuangBoFragment()
    {

    }

    public static GuangBoFragment newInstance() {
        
        Bundle args = new Bundle();

        GuangBoFragment fragment = new GuangBoFragment();
        fragment.setArguments(args);
        return fragment;
    }
    @Override
    protected void initViews() {
        super.initViews();
    }

    @Override
    protected void loadData() {
        super.loadData();
        OkHttpUtils.get(Urls.GUANGBO, null);
    }

    @Override
    protected void postEventResult(@NonNull EventMessage message) {
        super.postEventResult(message);
        if (Urls.GUANGBO.equals(message.type)) {
            Gson gson = new Gson();
            DianShiEntity[] dianShiEntities = gson.fromJson(message.result, DianShiEntity[].class);
            List<DianShiEntity> dianShiLists = new ArrayList<>();
            dianShiLists.addAll(Arrays.asList(dianShiEntities));
            DianShiBaseAdapter dianShiBaseAdapter = new DianShiBaseAdapter(getContext(), dianShiLists);
            listView.setAdapter(dianShiBaseAdapter);
            dianShiBaseAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
